package fudan.se.project.repository.projection.customized;

import fudan.se.project.domain.conference.post.Rebuttal;
import fudan.se.project.domain.conference.production.ReviewCopy;
import fudan.se.project.domain.conference.production.ReviewInfo;
import fudan.se.project.repository.projection.ReviewInfoProjection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class ReviewFromCopyProjection extends ReviewInfoProjection {

    private final ReviewCopy reviewCopy;

    public ReviewFromCopyProjection(ReviewCopy reviewCopy) {
        super(reviewCopy.getReviewInfo());
        this.reviewCopy = reviewCopy;
    }

    public ReviewFromCopyProjection(ReviewCopy reviewCopy, Rebuttal rebuttal) {
        super(reviewCopy.getReviewInfo(), rebuttal);
        this.reviewCopy = reviewCopy;
    }


    @Override
    public int getReviewInfoState() {
        ReviewInfo.ReviewInfoState state = this.reviewCopy.getReviewInfoState();
        return state == null ? -1 : state.ordinal();
    }

    @Override
    public String getComment() {
        return reviewCopy.getComment();
    }

    @Override
    public int getReviewConfidence() {
        ReviewInfo.ReviewConfidence confidence = this.reviewCopy.getReviewConfidence();
        return confidence == null ? -1 : confidence.ordinal();
    }


    public static ReviewFromCopyProjection project(ReviewCopy reviewCopy) {
        return new ReviewFromCopyProjection(reviewCopy);
    }

    public static ReviewFromCopyProjection project(ReviewCopy reviewCopy, Rebuttal rebuttal) {
        return new ReviewFromCopyProjection(reviewCopy, rebuttal);
    }


    public static List<ReviewInfoProjection> projectReviewCopies(Collection<ReviewCopy> values) {
        ArrayList<ReviewInfoProjection> arrayList = new ArrayList<>(values.size());
        for (ReviewCopy value : values) {
            arrayList.add(project(value));
        }
        return arrayList;
    }

}
